#include <QtGui>

#include "mainmenu.h"
#include "ui_mainmenu.h"



MainMenu::MainMenu(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainMenu)
{
    ui->setupUi(this);
    difficultySelected = false;
    modeSelected = false;
    userName = "";

    QObject::connect(ui->actionHelp, SIGNAL(triggered()), this, SLOT(on_actionHelpTriggered()));
}

MainMenu::~MainMenu()
{
    delete ui;
}

void MainMenu::on_radioEasy_clicked()
{
    difficultySelected = true;
    difficulty = "easy";
    repaint();
}

void MainMenu::on_radioNormal_clicked()
{
    difficultySelected = true;
    difficulty = "normal";
    repaint();
}

void MainMenu::on_radioHard_clicked()
{
    difficultySelected = true;
    difficulty = "hard";
    repaint();
}



void MainMenu::on_lineEditUsername_editingFinished()
{
    userName = ui->lineEditUsername->text();
    repaint();
}

void MainMenu::on_btnPlay_clicked()
{
    if (userName.trimmed() == "") {
        QMessageBox::information(this, "Wait just a minute!", "You didn't enter your name :(");
        return;
    } else {
        emit doneSelecting(difficulty, mode, userName);
        close();
    }
}

void MainMenu::paintEvent(QPaintEvent *ev) {
    if (difficultySelected && modeSelected) {
        ui->btnPlay->setEnabled(true);
    }
}

void MainMenu::on_radioSinglePlayer_clicked()
{
    modeSelected = true;
    mode = "singleplayer";
    repaint();
}

void MainMenu::on_radioTwoPlayer_clicked()
{
    modeSelected = true;
    mode = "twoplayer";
    repaint();
}

void MainMenu::on_actionHelpTriggered()
{
    HelpDialog h(this);
    h.show();

    if(h.exec() == QDialog::Accepted)
    {

    }

}
void MainMenu::on_newGame() {
    show();

}

